const api = require("../../server/Api.js");
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order: {},
    lastHistory: {},
    id: "",
    showCancelDialog: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id
    })
  },
  onShow: function() {
    this.refreshData()
  },
  refreshData() {
    let that = this;
    api.refundDetail2(that.data.id).then(res => {
      that.setData({
        order: res.refundOrder,
        lastHistory: JSON.parse(res.listHistory[res.listHistory.length - 1].remark)
      })
    }).catch(msg => {
      console.log(msg)
    })
  },
  cancel() {
    this.setData({
      showCancelDialog: true
    })
  },
  hiddenDialog() {
    this.setData({
      showCancelDialog: false
    })
  },
  onConfirm(orderId) {
    app.showLoading()
    let params = {
      "refundId": this.data.order.id
    }
    api.refundCancel(params).then(res => {
      tt.hideLoading()
      this.refreshData();
    }).catch(msg => {
      tt.hideLoading()
      let message = typeof msg == "string" ? msg : msg.message;
      app.showToast(message);
    })
  },
  alter(e) {
    tt.navigateTo({
      url: '../after-sales-choose/after-sales-choose?sid=' + this.data.order.id,
    })
  },
  tixing(e) {
    app.showToast("暂不支持此功能")
  }
})